package com.ruoyi.web.controller.system;

import com.ruoyi.cms.domain.*;
import com.ruoyi.cms.service.*;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.system.service.ISysDictDataService;
import com.ruoyi.system.service.ISysDictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.cms.domain.SysCmsLink;
import java.util.List;
import org.springframework.ui.Model;
import com.ruoyi.cms.domain.CmsBannerItem;
import com.ruoyi.cms.domain.SysCmsFeedback;
import com.ruoyi.cms.service.ISysCmsFeedbackService;
import com.ruoyi.cms.domain.SysCmsMaterial;
import com.ruoyi.common.core.domain.entity.SysDictType;
/**
 * 首页
 *
 * @author ruoyi
 */
@Controller
public class SysIndexController
{
    /** 系统基础配置 */
    @Autowired
    private RuoYiConfig ruoyiConfig;

    @Autowired
    private ISysCmsLinkService sysCmsLinkService;

    @Autowired
    private ICmsBannerItemService cmsBannerItemService;

    @Autowired
    private ICmsBannerService cmsBannerService;

    @Autowired
    private ISysCmsFeedbackService sysCmsFeedbackService;

    @Autowired
    private ISysCmsMaterialService sysCmsMaterialService;

    @Autowired
    private ISysDictTypeService dictTypeService;

    @Autowired
    private ISysDictDataService dictDataService;
    /**
     * 访问首页，提示语
     */
    @RequestMapping("/")
    public String index(Model model)
    {

        SysCmsLink sysCmsLink = new SysCmsLink();
        sysCmsLink.setStatus(1L);
        //友情链接
        List<SysCmsLink> cmsLinkList = sysCmsLinkService.selectSysCmsLinkList(sysCmsLink);
        cmsLinkList.forEach(link -> System.out.println(link.getName() + " - " + link.getLink()));
        model.addAttribute("linkList", cmsLinkList);

        //媒体 coverage
        CmsBanner cmsBanner = new CmsBanner();
        cmsBanner.setStatus(1L);
        cmsBanner.setMark("mediaCoverage");
        CmsBanner banner = cmsBannerService.selectCmsBannerByMark(cmsBanner);
        System.out.println("banner：" + banner);
        model.addAttribute("banner", banner);
        CmsBannerItem cmsBannerItem = new CmsBannerItem();
        cmsBannerItem.setStatus(1L);
        cmsBannerItem.setBannerId(banner.getId());
        List<CmsBannerItem> cmsBannerItemList = cmsBannerItemService.selectCmsBannerItemList(cmsBannerItem);
        model.addAttribute("bannerItemList", cmsBannerItemList);

        //业主访谈 owner
        cmsBanner.setMark("owner");
        CmsBanner ownerBanner = cmsBannerService.selectCmsBannerByMark(cmsBanner);
        System.out.println("banner：" + ownerBanner);
        model.addAttribute("ownerBanner", ownerBanner);
        cmsBannerItem.setStatus(1L);
        cmsBannerItem.setBannerId(ownerBanner.getId());
        List<CmsBannerItem> ownerCmsBannerItemList = cmsBannerItemService.selectCmsBannerItemList(cmsBannerItem);
        model.addAttribute("ownerCmsBannerItemList", ownerCmsBannerItemList);

        //RENOSY？ select

        //业主访谈 owner
        cmsBanner.setMark("select");
        CmsBanner selectBanner = cmsBannerService.selectCmsBannerByMark(cmsBanner);
        System.out.println("banner：" + selectBanner);
        model.addAttribute("selectBanner", selectBanner);
        cmsBannerItem.setStatus(1L);
        cmsBannerItem.setBannerId(selectBanner.getId());
        List<CmsBannerItem> selectCmsBannerItem = cmsBannerItemService.selectCmsBannerItemList(cmsBannerItem);
        model.addAttribute("selectCmsBannerItem", selectCmsBannerItem);

        //优点 merit
        cmsBanner.setMark("merit");
        CmsBanner meritBanner = cmsBannerService.selectCmsBannerByMark(cmsBanner);
        System.out.println("banner：" + meritBanner);
        model.addAttribute("meritBanner", meritBanner);
        cmsBannerItem.setStatus(1L);
        cmsBannerItem.setBannerId(meritBanner.getId());
        List<CmsBannerItem>  meritCmsBannerItem = cmsBannerItemService.selectCmsBannerItemList(cmsBannerItem);
        model.addAttribute("meritCmsBannerItem", meritCmsBannerItem);

        //结构 structure
        cmsBanner.setMark("structure");
        CmsBanner structureBanner = cmsBannerService.selectCmsBannerByMark(cmsBanner);
        System.out.println("structureBanner：" + structureBanner);
        model.addAttribute("structureBanner", structureBanner);

        //反馈 feedback
        SysCmsFeedback sysCmsFeedback = new SysCmsFeedback();
        sysCmsFeedback.setStatus(1L);
        List<SysCmsFeedback> feedbackList = sysCmsFeedbackService.selectSysCmsFeedbackList(sysCmsFeedback);

        model.addAttribute("feedbackList", feedbackList);

        //首页背景 图片
        SysCmsMaterial sysCmsMaterial = new SysCmsMaterial();
        sysCmsMaterial.setMaterialMark("homeBannerBg");
        SysCmsMaterial homeBannerBg = sysCmsMaterialService.selectSysCmsMaterialByMaterialMark(sysCmsMaterial);
        model.addAttribute("homeBannerBg", homeBannerBg);

        System.out.println("数据量：" + homeBannerBg);


        //黑色 LOGO 图片
        sysCmsMaterial.setMaterialMark("blackLogo");
        SysCmsMaterial blackLogo = sysCmsMaterialService.selectSysCmsMaterialByMaterialMark(sysCmsMaterial);
        model.addAttribute("blackLogo", blackLogo);

        //白色 LOGO 图片
        sysCmsMaterial.setMaterialMark("whiteLogo");
        SysCmsMaterial whiteLogo = sysCmsMaterialService.selectSysCmsMaterialByMaterialMark(sysCmsMaterial);
        model.addAttribute("whiteLogo", whiteLogo);

        //site_config

        SysDictType dictType = dictTypeService.selectDictTypeByType("site_config");
        System.out.println("dictType：" + dictType);
        SysDictData SysDictData = new SysDictData();
        SysDictData.setDictType(dictType.getDictType());
        List<SysDictData> dictDatalist = dictDataService.selectDictDataList(SysDictData);
        //System.out.println("dictDatalist：" + dictDatalist);

        if(dictDatalist.size() > 0){
            dictDatalist.forEach(data ->
                    model.addAttribute("siteConfig"+data.getDictValue(), data.getDictLabel())
            );

            dictDatalist.forEach(data ->
                    model.addAttribute("remark"+data.getDictValue(), data.getRemark())
            );

        }




        //首页背景 图片
//        SysCmsMaterial sysCmsMaterial = new SysCmsMaterial();
//        sysCmsMaterial.setMaterialMark("homeBannerBg");
//        SysCmsMaterial homeBannerBg = sysCmsMaterialService.selectSysCmsMaterialByMaterialMark(sysCmsMaterial);
//        model.addAttribute("homeBannerBg", homeBannerBg);

//        System.out.println("数据量：" + cmsBannerList.size());
//        cmsBannerList.forEach(link -> System.out.println(link.getTitle() + " - " + link.getCoverImage()));
        return "index";  // 对应 templates/index.html
    }
}
